package com.yst.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yst.common.annotation.DataScope;
import com.yst.common.annotation.RateLimiter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yst.common.annotation.Log;
import com.yst.common.core.controller.BaseController;
import com.yst.common.core.domain.AjaxResult;
import com.yst.common.enums.BusinessType;
import com.yst.system.domain.SellOrder;
import com.yst.system.service.ISellOrderService;
import com.yst.common.utils.poi.ExcelUtil;
import com.yst.common.core.page.TableDataInfo;

/**
 * 订单信息Controller
 * 
 * @author hoj
 * @date 2024-05-10
 */
@RestController
@RequestMapping("/system/order")
public class SellOrderController extends BaseController {
    @Autowired
    private ISellOrderService sellOrderService;

    /**
     * 查询订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    @DataScope(deptAlias = "a")
    public TableDataInfo list(SellOrder sellOrder)
    {
        startPage();
        List<SellOrder> list = sellOrderService.selectSellOrderList(sellOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SellOrder sellOrder)
    {
        List<SellOrder> list = sellOrderService.selectSellOrderList(sellOrder);
        ExcelUtil<SellOrder> util = new ExcelUtil<SellOrder>(SellOrder.class);
        util.exportExcel(response, list, "订单信息数据");
    }

    /**
     * 导出订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exportOrderInfo")
    public void exportOrderInfo(HttpServletResponse response, SellOrder sellOrder)
    {
         sellOrderService.exportOrderInfo(sellOrder,response);
    }

    /**
     * 获取订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{sellOrderId}")
    public AjaxResult getInfo(@PathVariable("sellOrderId") Long sellOrderId)
    {
        return success(sellOrderService.selectSellOrderBySellOrderId(sellOrderId));
    }

    /**
     * 新增订单信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    @RateLimiter
    public AjaxResult add(@RequestBody SellOrder sellOrder)
    {
        return toAjax(sellOrderService.insertSellOrder(sellOrder));
    }

    /**
     * 修改订单信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @RateLimiter
    public AjaxResult edit(@RequestBody SellOrder sellOrder)
    {
        return toAjax(sellOrderService.updateSellOrder(sellOrder));
    }

    /**
     * 删除订单信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sellOrderIds}")
    public AjaxResult remove(@PathVariable Long[] sellOrderIds)
    {
        return toAjax(sellOrderService.deleteSellOrderBySellOrderIds(sellOrderIds));
    }
}
